package leetcode_day._2023._11;

import java.util.Arrays;

/**
 * 1657.确定两个字符串是否接近
 * 算法: 排序
 *
 * @author yezh
 * @date 2023/11/30 9:41
 */
public class _30 {

    public static boolean closeStrings(String word1, String word2) {
        int len1 = word1.length(), len2 = word2.length();
        if (len1 != len2) return false;
        int[] cnt1 = new int[26], cnt2 = new int[26];
        for (int i = 0; i < len1; i++) {
            cnt1[word1.charAt(i) - 'a']++;
            cnt2[word2.charAt(i) - 'a']++;
        }
        for (int i = 0; i < 26; i++) if (cnt1[i] == 0 && cnt2[i] != 0 || cnt1[i] != 0 && cnt2[i] == 0) return false;
        Arrays.sort(cnt1);
        Arrays.sort(cnt2);
        for (int i = 0; i < 26; i++) if (cnt1[i] != cnt2[i]) return false;
        return true;
    }

}
